<%--
  Created by IntelliJ IDEA.
  User: zhli
  Date: 2022/10/20
  Time: 15:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.bson.Document" %>
<%@ page import="com.mongodb.client.*" %>
<%@ page import="java.util.regex.Pattern" %>
<%@ page import="org.bson.conversions.Bson" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="javax.print.Doc" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>登录系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<jsp:include page="major.jsp"></jsp:include>

<%
    String url = "mongodb://g08:abc%408@mongo.zhledu.cn:27017/g08";
    MongoClient client = MongoClients.create(url);
    MongoIterable<String> names = client.listDatabaseNames();
    MongoDatabase g08 = client.getDatabase("g08");
    MongoCollection<Document> collection = g08.getCollection("student");
    String username=request.getParameter("username");
    String password= request.getParameter("password");
    Document login=new Document();
    login.append("username",username);
    login.append("password",password);
    FindIterable<Document> list = collection.find(login).limit(1);
    for(Document d : list){
        session.setAttribute("isLogin","1");
        response.sendRedirect("index.jsp");
    }
%>
<div class="container">
    <center>
        <h1>登录系统</h1>
    </center>
    <form class="form-horizontal" method="post" action="login.jsp">
        <div class="form-group">
            <label class="control-label col-sm-2">用户名:</label>
            <div class="col-sm-4">
                <input id="username" name="username" class="form-control">
            </div>
            <label class="control-label col-sm-2"> 密码:</label>
            <div class="col-sm-4">
                <input id="password" name="password" class="form-control">
            </div>
        </div>
        <center>

            <button id="submit" type="submit" class="btn btn-info glyphicon glyphicon-save">登录</button>
            <button type="reset" class="btn btn-warning glyphicon glyphicon-refresh">重置</button>
        </center>
    </form>
</div>


<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>

<%
    client.close();
%>
</body>
</html>
